public class t713_2 {
    //双指针滑动窗口
    public static void main(String[] args) {
        int arr[] = {1,1,1};
        int k = 2;
        int num = numSubarrayProductLessThanK(arr, k);
        System.out.println(num);
    }

    public static int numSubarrayProductLessThanK(int[] nums, int k) {
       int num = 0;
       int left = 0;
       int right = 0;
       int tmp = 1;
       while (right<nums.length){//右指针遍历数组
           tmp *= nums[right];
           while (tmp>=k){//大于等于预设值移动左指针
               tmp/=nums[left];//移出左元素
               left++;
           }
           num += right-left+1;
           right++;
       }
       return  num;
    }

}
